package com.edu.hre.db.config;

/**
 * Created by IntelliJ IDEA.
 * User: Nguyen The Tung
 * Date: Dec 26, 2009
 * Time: 11:13:28 AM
 */

import org.apache.log4j.Logger;

import java.sql.*;

public class BaseDAO {
	private static final Logger logger = Logger.getLogger(BaseDAO.class);

	// ==========================================================================
	/* CallableStatement close */
	public void releaseConnection(Connection conn, CallableStatement calStmt) {
		try {
			if (calStmt != null)
				calStmt.close();
		} catch (SQLException e) {
			logger.error(e);
		}

		DBPool.putConnection(conn);
	}

	/* CallableStatement and ResultSet close */
	public void releaseConnection(Connection conn, CallableStatement calStmt,
			ResultSet rs) {
		releaseConnection(conn, calStmt);
		try {
			if (rs != null)
				rs.close();
		} catch (SQLException e) {
			logger.error(e);
		}
	}

	/* PreparedStatement close */
	public void releaseConnection(Connection conn, PreparedStatement preStmt) {
		try {
			if (preStmt != null)
				preStmt.close();
		} catch (SQLException e) {
			logger.error(e);
		}

		DBPool.putConnection(conn);
	}

	/* PreparedStatement and ResultSet close */
	public void releaseConnection(Connection conn, PreparedStatement preStmt,
			ResultSet rs) {
		releaseConnection(conn, preStmt);
		try {
			if (rs != null)
				rs.close();
		} catch (SQLException e) {
			logger.error(e);
		}
	}

	public void releaseConnection(Connection conn, PreparedStatement preStmt,
			Statement stmt, ResultSet rs) {
		releaseConnection(conn, preStmt, rs);
		try {
			if (stmt != null)
				stmt.close();
		} catch (SQLException e) {
			logger.error(e);
		}
	}
}